home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 15 / CU Amiga Magazine's Super CD-ROM 15 (1997)(EMAP Images)(GB)[!][issue 1997-10].iso / CUCD / Graphics / Ghostscript / source / libpng / pngget.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-12  |  8.1 KB  |  301 lines

  1.  
  2. /* pngget.c - retrieval of values from info struct
  3.  
  4.    libpng 1.0 beta 6 - version 0.96
  5.    For conditions of distribution and use, see copyright notice in png.h
  6.    Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
  7.    Copyright (c) 1996, 1997 Andreas Dilger
  8.    May 12, 1997
  9.    */
  10.  
  11. #define PNG_INTERNAL
  12. #include "png.h"
  13.  
  14. png_uint_32
  15. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  16. {
  17.    if (info_ptr != NULL)
  18.       return(info_ptr->valid & flag);
  19.    else
  20.       return(0);
  21. }
  22.  
  23. png_uint_32
  24. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  25. {
  26.    if (info_ptr != NULL)
  27.       return(info_ptr->rowbytes);
  28.    else
  29.       return(0);
  30. }
  31.  
  32. png_byte
  33. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  34. {
  35.    if (info_ptr != NULL)
  36.       return(info_ptr->channels);
  37.    else
  38.       return(0);
  39. }
  40.  
  41. png_bytep
  42. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  43. {
  44.    if (info_ptr != NULL)
  45.       return(info_ptr->signature);
  46.    else
  47.       return(NULL);
  48. }
  49.  
  50. #if defined(PNG_READ_bKGD_SUPPORTED)
  51. png_uint_32
  52. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  53.    png_color_16p *background)
  54. {
  55.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_bKGD &&
  56.       background != NULL)
  57.    {
  58.       png_debug1(1, "in %s retrieval function\n", "bKGD");
  59.       *background = &(info_ptr->background);
  60.       return (PNG_INFO_bKGD);
  61.    }
  62.    return (0);
  63. }
  64. #endif
  65.  
  66. #if defined(PNG_READ_cHRM_SUPPORTED)
  67. png_uint_32
  68. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  69.    double *white_x, double *white_y, double *red_x, double *red_y,
  70.    double *green_x, double *green_y, double *blue_x, double *blue_y)
  71. {
  72.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_cHRM)
  73.    {
  74.       png_debug1(1, "in %s retrieval function\n", "cHRM");
  75.       if (white_x != NULL)
  76.          *white_x = (double)info_ptr->x_white;
  77.       if (white_y != NULL)
  78.          *white_y = (double)info_ptr->y_white;
  79.       if (red_x != NULL)
  80.          *red_x = (double)info_ptr->x_red;
  81.       if (red_y != NULL)
  82.          *red_y = (double)info_ptr->y_red;
  83.       if (green_x != NULL)
  84.          *green_x = (double)info_ptr->x_green;
  85.       if (green_y != NULL)
  86.          *green_y = (double)info_ptr->y_green;
  87.       if (blue_x != NULL)
  88.          *blue_x = (double)info_ptr->x_blue;
  89.       if (blue_y != NULL)
  90.          *blue_y = (double)info_ptr->y_blue;
  91.       return (PNG_INFO_cHRM);
  92.    }
  93.    return (0);
  94. }
  95. #endif
  96.  
  97. #if defined(PNG_READ_gAMA_SUPPORTED)
  98. png_uint_32
  99. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  100. {
  101.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_gAMA &&
  102.       file_gamma != NULL)
  103.    {
  104.       png_debug1(1, "in %s retrieval function\n", "gAMA");
  105.       *file_gamma = (double)info_ptr->gamma;
  106.       return (PNG_INFO_gAMA);
  107.    }
  108.    return (0);
  109. }
  110. #endif
  111.  
  112. #if defined(PNG_READ_hIST_SUPPORTED)
  113. png_uint_32
  114. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  115. {
  116.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_hIST && hist != NULL)
  117.    {
  118.       png_debug1(1, "in %s retrieval function\n", "hIST");
  119.       *hist = info_ptr->hist;
  120.       return (PNG_INFO_hIST);
  121.    }
  122.    return (0);
  123. }
  124. #endif
  125.  
  126. png_uint_32
  127. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  128.    png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  129.    int *color_type, int *interlace_type, int *compression_type,
  130.    int *filter_type)
  131.    
  132. {
  133.    if (info_ptr != NULL && width != NULL && height != NULL &&
  134.       bit_depth != NULL && color_type != NULL)
  135.    {
  136.       png_debug1(1, "in %s retrieval function\n", "IHDR");
  137.       *width = info_ptr->width;
  138.       *height = info_ptr->height;
  139.       *bit_depth = info_ptr->bit_depth;
  140.       *color_type = info_ptr->color_type;
  141.       if (compression_type != NULL)
  142.          *compression_type = info_ptr->compression_type;
  143.       if (filter_type != NULL)
  144.          *filter_type = info_ptr->filter_type;
  145.       if (interlace_type != NULL)
  146.          *interlace_type = info_ptr->interlace_type;
  147.       return (1);
  148.    }
  149.    return (0);
  150. }
  151.  
  152. #if defined(PNG_READ_oFFs_SUPPORTED)
  153. png_uint_32
  154. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  155.    png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
  156. {
  157.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_oFFs &&
  158.       offset_x != NULL && offset_y != NULL && unit_type != NULL)
  159.    {
  160.       png_debug1(1, "in %s retrieval function\n", "oFFs");
  161.       *offset_x = info_ptr->x_offset;
  162.       *offset_y = info_ptr->y_offset;
  163.       *unit_type = (int)info_ptr->offset_unit_type;
  164.       return (PNG_INFO_oFFs);
  165.    }
  166.    return (0);
  167. }
  168. #endif
  169.  
  170. #if defined(PNG_READ_pCAL_SUPPORTED)
  171. png_uint_32
  172. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  173.    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  174.    png_charp *units, png_charpp *params)
  175. {
  176.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
  177.       purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  178.       nparams != NULL && units != NULL && params != NULL)
  179.    {
  180.       png_debug1(1, "in %s retrieval function\n", "pCAL");
  181.       *purpose = info_ptr->pcal_purpose;
  182.       *X0 = info_ptr->pcal_X0;
  183.       *X1 = info_ptr->pcal_X1;
  184.       *type = (int)info_ptr->pcal_type;
  185.       *nparams = (int)info_ptr->pcal_nparams;
  186.       *units = info_ptr->pcal_units;
  187.       *params = info_ptr->pcal_params;
  188.       return (PNG_INFO_pCAL);
  189.    }
  190.    return (0);
  191. }
  192. #endif
  193.  
  194. #if defined(PNG_READ_pHYs_SUPPORTED)
  195. png_uint_32
  196. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  197.    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  198. {
  199.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs &&
  200.       res_x != NULL && res_y != NULL && unit_type != NULL)
  201.    {
  202.       png_debug1(1, "in %s retrieval function\n", "pHYs");
  203.       *res_x = info_ptr->x_pixels_per_unit;
  204.       *res_y = info_ptr->y_pixels_per_unit;
  205.       *unit_type = (int)info_ptr->phys_unit_type;
  206.       return (PNG_INFO_pHYs);
  207.    }
  208.    return (0);
  209. }
  210. #endif
  211.  
  212. png_uint_32
  213. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  214.    int *num_palette)
  215. {
  216.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE && palette != NULL)
  217.    {
  218.       png_debug1(1, "in %s retrieval function\n", "PLTE");
  219.       *palette = info_ptr->palette;
  220.       *num_palette = info_ptr->num_palette;
  221.       png_debug1(3, "num_palette = %d\n", *num_palette);
  222.       return (PNG_INFO_PLTE);
  223.    }
  224.    return (0);
  225. }
  226.  
  227. #if defined(PNG_READ_sBIT_SUPPORTED)
  228. png_uint_32
  229. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  230. {
  231.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT && sig_bit != NULL)
  232.    {
  233.       png_debug1(1, "in %s retrieval function\n", "sBIT");
  234.       *sig_bit = &(info_ptr->sig_bit);
  235.       return (PNG_INFO_sBIT);
  236.    }
  237.    return (0);
  238. }
  239. #endif
  240.  
  241. #if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
  242. png_uint_32
  243. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  244.    int *num_text)
  245. {
  246.    if ((info_ptr != NULL) || (info_ptr->num_text > 0))
  247.    {
  248.       png_debug1(1, "in %s retrieval function\n",
  249.          (png_ptr->chunk_name[0] == '\0' ? "text" : png_ptr->chunk_name));
  250.       if (text_ptr != NULL)
  251.          *text_ptr = info_ptr->text;
  252.       if (num_text != NULL)
  253.          *num_text = info_ptr->num_text;
  254.       return (info_ptr->num_text);
  255.    }
  256.    return(0);
  257. }
  258. #endif
  259.  
  260. #if defined(PNG_READ_tIME_SUPPORTED)
  261. png_uint_32
  262. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  263. {
  264.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME && mod_time != NULL)
  265.    {
  266.       png_debug1(1, "in %s retrieval function\n", "tIME");
  267.       *mod_time = &(info_ptr->mod_time);
  268.       return (PNG_INFO_tIME);
  269.    }
  270.    return (0);
  271. }
  272. #endif
  273.  
  274. #if defined(PNG_READ_tRNS_SUPPORTED)
  275. png_uint_32
  276. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  277.    png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  278. {
  279.    if (info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
  280.    {
  281.       png_debug1(1, "in %s retrieval function\n", "tRNS");
  282.       if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE && trans != NULL)
  283.       {
  284.           *trans = info_ptr->trans;
  285.       }
  286.       else if (trans_values != NULL)
  287.       {
  288.          *trans_values = &(info_ptr->trans_values);
  289.       }
  290.       else
  291.       {
  292.          return (0);
  293.       }
  294.       *num_trans = info_ptr->num_trans;
  295.       return (PNG_INFO_tRNS);
  296.    }
  297.    return (0);
  298. }
  299. #endif
  300.  
  301.